package com.eshop.service.impl.mongodb;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import com.eshop.dao.mongodb.ShopCertDao;
import com.eshop.frameworks.core.dao.DAO;
import com.eshop.frameworks.core.entity.PageEntity;
import com.eshop.frameworks.core.service.impl.AbstractService;
import com.eshop.model.mongodb.ShopCert;
import com.eshop.service.mongodb.ShopCertService;

@Service("shopCertService")
public class ShopCertServiceImpl extends AbstractService<ShopCert, String> implements ShopCertService {
	@Autowired
	private ShopCertDao shopCertDao;

	@Override
	public DAO<ShopCert, String> getDao() {
		return shopCertDao;
	}
	@Override
	public ShopCert findByUserId(String userId) {
		return getDao().findOne(new Query(Criteria.where("userId").is(userId)), ShopCert.class);
	}
	@Override
	public List<ShopCert> findList(PageEntity page) {
		Query query = new Query();
		List<Order> orders = new ArrayList<Order>();
		orders.add(new Order(Direction.ASC,"status"));
		orders.add(new Order(Direction.DESC,"createTime"));
		query.with(new Sort(orders));
		query.skip(page.getStartRow()).limit(page.getPageSize());
		return getDao().findList(query, ShopCert.class);
	}
	

}
